package net.moon;

import java.io.*;
import java.time.LocalDate;
import java.util.StringJoiner;

/**
 * @author moonlan
 * date 2021/4/27 8:09
 */
@SuppressWarnings(value = "unused")
public class Weekly implements Serializable {

    private String name;
    private LocalDate date;
    private String content;

    public Weekly(String name, LocalDate date, String content) {
        this.name = name;
        this.date = date;
        this.content = content;
    }

    public String getName() {
        return name;
    }

    public Weekly setName(String name) {
        this.name = name;
        return this;
    }

    public LocalDate getDate() {
        return date;
    }

    public Weekly setDate(LocalDate date) {
        this.date = date;
        return this;
    }

    public String getContent() {
        return content;
    }

    public Weekly setContent(String content) {
        this.content = content;
        return this;
    }

    protected Object deepClone() {
        try {
            FileOutputStream outputStream = new FileOutputStream("./obj.ser");
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeObject(this);
            objectOutputStream.close();
            outputStream.close();

            FileInputStream inputStream = new FileInputStream("./obj.ser");
            ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
            return objectInputStream.readObject();
        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", Weekly.class.getSimpleName() + "[", "]")
                .add("name='" + name + "'")
                .add("date=" + date)
                .add("content='" + content + "'")
                .toString();
    }
}
